package com.i2863.receipt.dao;

import com.i2863.receipt.entity.Receipt;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Collection;
import java.util.List;

/**
 * Created by Administrator on 2018/6/8.
 */
public interface ReceiptRepository extends JpaRepository<Receipt,Integer>,JpaSpecificationExecutor<Receipt>{

    /**
     * 按发票代码查询
     * @param code
     * @return
     */
    public Receipt findByCode(String code);

    /**
     * 查询参与此次活动的报名者列表
     * @param activityId 活动id
     * @return  报名者列表
     */
    public List<Receipt> findByActivityIdOrderByIdAsc(Integer activityId,Pageable pageable);


    /**
     * 参与发票抽奖的用户总数
     * @param activityId
     * @return 抽奖的用户总数
     */
    public Integer countByActivityId(Integer activityId);

    /**
     * 查询活动的所有报名者
     * @param activityId  活动id
     * @return 活动的所有报名者
     */
    @Query(value="select id from d_receipt where activity_id = :activityId ",nativeQuery = true)
    public List<Integer> findByActivityId(@Param("activityId") Integer activityId);

    /**
     * 通过id列表查找报名者
     * @param ids id列表
     * @return   报名者
     */
    List<Receipt> findByIdIn(Collection<Integer> ids);

}
